from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.core.urlresolvers import reverse
from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.sitemaps import ping_google

@staff_member_required
def main(request, template_name="s_te/admin/main.html"):
    """
    Site admin
    """
    if request.POST:
        try:
            ping_google()
            request.user.message_set.create(message="Google ping succeeded.")
            return HttpResponseRedirect(reverse('s_te_admin_main'))
        except Exception:
            request.user.message_set.create(message="Google ping failed!")
            return HttpResponseRedirect(reverse('s_te_admin_main'))
        
    return render_to_response(template_name, {'nav_page': 's_te_admin_main'},
                              context_instance=RequestContext(request))
    